from utils.log_util import logger
'''
if __name__ == '__main__':
    log = logger().getlog()
    log.info("test info log")
    log.error("test error log")
'''
import yaml
import json

# 你的 JSON 数据
response_data = {
    "code": "SUCCESS",
    "errMsg": "",
    "data": [
        {
            "id": 32213,
            "title": "博客标题",
            "content": "博客内容",
            "userId": 3,
            "deleteFlag": 0,
            "createTime": "2025-03-18 11:41",
            "updateTime": "2025-03-18T03:41:34.000+00:00",
            "loginUser": False
        },
        {
            "id": 32214,
            "title": "接口测试",
            "content": "##测试接口",
            "userId": 3,
            "deleteFlag": 0,
            "createTime": "2025-10-05 22:10",
            "updateTime": "2025-10-05T14:10:12.000+00:00",
            "loginUser": False
        }
    ]
}


# 方法1：直接提取所有 id
def extract_ids_to_yaml(data):
    # 提取所有 id
    blog_ids = [item["id"] for item in data["data"]]

    # 保存到 YAML 文件
    # with open(output_file, 'w', encoding='utf-8') as f:
    #     yaml.dump(blog_ids, f, allow_unicode=True, default_flow_style=False)
    #
    # print(f"✅ 已保存 {len(blog_ids)} 个 ID 到 {output_file}")
    return blog_ids

if __name__ == '__main__':
    # 使用示例
    ids = extract_ids_to_yaml(response_data)
    print("提取的 ID:", ids)
